﻿using MeterReader.WebApi.Models;

namespace MeterReader.WebApi.Extensions
{
    public static class TMeterExtensions
    {
        public static List<NewTMeter> ToNewTMeterList(this TMeter tMeter)
        {
            var newTMeters = new List<NewTMeter>();
            var date = (DateTime)tMeter.GetType().GetProperty($"Date").GetValue(tMeter, null);
            for (int i = 1; i <= 170; i++)
            {
                // Use reflection to get the value of each column
                var value = (double)tMeter.GetType().GetProperty($"Col{i}").GetValue(tMeter, null);

                var newTMeter = new NewTMeter
                {
                    Value = value,
                    Timestamp = DateTime.Now,
                    NameId = i,
                };

                newTMeters.Add(newTMeter);
            }

            return newTMeters;
        }
    }
}
